package cn.boysoft.core.spring;

import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.xml.XmlReaderContext;
import org.springframework.context.annotation.ComponentScanBeanDefinitionParser;
import org.w3c.dom.Element;

import cn.boysoft.core.server.MainServer;
/**
 * 
 * @author 付厚俊
 * CreateTime 2013-4-4 下午5:09:32
 */
public class JeeComponentScanBeanDefinitionParser extends
		ComponentScanBeanDefinitionParser {
	 private final static Logger LOGGER = LoggerFactory.getLogger(JeeComponentScanBeanDefinitionParser.class);

	 @Override
	protected void registerComponents(XmlReaderContext readerContext,
			Set<BeanDefinitionHolder> beanDefinitions, Element element) {
		super.registerComponents(readerContext, beanDefinitions, element);
		this.registerService(beanDefinitions);
	}
	 
	protected void registerService(Set<BeanDefinitionHolder> beanDefinitions) {
		if(beanDefinitions != null){
			for(BeanDefinitionHolder beanDefinitionHolder : beanDefinitions){
				String beanName = beanDefinitionHolder.getBeanName();
				if(beanName != null){
					MainServer.serviceInfos.add(beanName);
				}else{
					LOGGER.error("ClassLoad", "Load "+beanName +"Error");
				}
			}
		}
	}
}
